home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / source / emacs-18.59src.lha / emacs-18.59 / src / emacs.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-11-22  |  18.5 KB  |  790 lines

  1. /* Fully extensible Emacs, running on Unix, intended for GNU.
  2.    Copyright (C) 1985, 1986, 1987, 1990 Free Software Foundation, Inc.
  3.  
  4. This file is part of GNU Emacs.
  5.  
  6. GNU Emacs is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 1, or (at your option)
  9. any later version.
  10.  
  11. GNU Emacs is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with GNU Emacs; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20.  
  21. /* This must precede sys/signal.h on certain machines.  */
  22. #include <sys/types.h>
  23. #include <signal.h>
  24. #include <errno.h>
  25.  
  26. #include "config.h"
  27. #ifdef NULL
  28. #undef NULL
  29. #endif
  30. #include "lisp.h"
  31. #undef NULL
  32. #include "commands.h"
  33.  
  34. /* Get FIONREAD, if it is available,
  35.    just to help decide whether SIGIO should be defined.  */
  36. #ifdef USG
  37. #include <termio.h>
  38. #include <fcntl.h>
  39. #else /* not USG */
  40. #ifndef VMS
  41. #include <sys/ioctl.h>
  42. #endif /* not VMS */
  43. #endif /* not USG */
  44.  
  45. /* Allow m- file to inhibit use of FIONREAD.  */
  46. #ifdef BROKEN_FIONREAD
  47. #undef FIONREAD
  48. #endif
  49.  
  50. /* We are unable to use interrupts if FIONREAD is not available,
  51.    so flush SIGIO so we won't try. */
  52. #ifndef FIONREAD
  53. #ifdef SIGIO
  54. #undef SIGIO
  55. #endif
  56. #endif
  57.  
  58. #include <stdio.h>
  59. #include <sys/file.h>
  60.  
  61. #ifdef VMS
  62. #include <ssdef.h>
  63. #endif
  64.  
  65. #if 0 /* fcntl.h was included above.  */
  66. #ifdef USG5
  67. #include <fcntl.h>
  68. #endif
  69. #endif
  70.  
  71. #ifdef BSD
  72. #include <sys/ioctl.h>
  73. #endif
  74.  
  75. #ifdef APOLLO
  76. #ifndef APOLLO_SR10
  77. #include <default_acl.h>
  78. #endif
  79. #endif
  80.  
  81. #ifdef AMIGA_DUMP
  82. #define HAVE_SHM        /* Simplifies the ifdefs */
  83. #endif
  84.  
  85. #ifndef O_RDWR
  86. #define O_RDWR 2
  87. #endif
  88.  
  89. #define PRIO_PROCESS 0
  90.  
  91. /* Command line args from shell, as list of strings */
  92. Lisp_Object Vcommand_line_args;
  93.  
  94. /* Hook run by `kill-emacs' before it does really anything.  */
  95. Lisp_Object Vkill_emacs_hook;
  96.  
  97. /* Set nonzero after Emacs has started up the first time.
  98.   Prevents reinitialization of the Lisp world and keymaps
  99.   on subsequent starts.  */
  100. int initialized;
  101.  
  102. /* Variable whose value is symbol giving operating system type */
  103. Lisp_Object Vsystem_type;
  104.   
  105. /* If non-zero, emacs should not attempt to use an window-specific code,
  106.    but instead should use the virtual terminal under which it was started */
  107. int inhibit_window_system;
  108.  
  109. #ifdef HAVE_X_WINDOWS
  110. /* If -d option is used, this variable points to the name of
  111.    the display to use.  */
  112. char *alternate_display;
  113. char **xargv;
  114. int xargc;
  115. #endif /* HAVE_X_WINDOWS */
  116.  
  117. #ifdef USG_SHARED_LIBRARIES
  118. /* If nonzero, this is the place to put the end of the writable segment
  119.    at startup.  */
  120.  
  121. unsigned int bss_end = 0;
  122. #endif
  123.  
  124. /* Nonzero means running Emacs without interactive terminal.  */
  125.  
  126. int noninteractive;
  127.  
  128. /* Value of Lisp variable `noninteractive'.
  129.    Normally same as C variable `noninteractive'
  130.    but nothing terrible happens if user sets this one.  */
  131.  
  132. int noninteractive1;
  133.  
  134. /* Signal code for the fatal signal that was received */
  135. int fatal_error_code;
  136.  
  137. /* Nonzero if handling a fatal error already */
  138. int fatal_error_in_progress;
  139.  
  140. /* Handle bus errors, illegal instruction, etc. */
  141. fatal_error_signal (sig)
  142.      int sig;
  143. {
  144. #ifdef BSD
  145.   int tpgrp;
  146. #endif /* BSD */
  147.  
  148.   fatal_error_code = sig;
  149.   signal (sig, SIG_DFL);
  150.  
  151.   /* If fatal error occurs in code below, avoid infinite recursion.  */
  152.   if (fatal_error_in_progress)
  153.     kill (getpid (), fatal_error_code);
  154.  
  155.   fatal_error_in_progress = 1;
  156.  
  157.   /* If we are controlling the terminal, reset terminal modes */
  158. #ifdef BSD
  159.   if (ioctl(0, TIOCGPGRP, &tpgrp) == 0
  160.       && tpgrp == getpgrp (0))
  161. #endif /* BSD */
  162.     {
  163.       reset_sys_modes ();
  164.       if (sig != SIGTERM)
  165.     fprintf (stderr, "Fatal error (%d).", sig);
  166.     }
  167.  
  168.   /* Clean up */
  169. #ifdef subprocesses
  170.   kill_buffer_processes (Qnil);
  171. #endif
  172.   Fdo_auto_save (Qt);
  173.  
  174. #ifdef CLASH_DETECTION
  175.   unlock_all_files ();
  176. #endif /* CLASH_DETECTION */
  177.  
  178. #ifdef VMS
  179.   kill_vms_processes ();
  180.   LIB$STOP (SS$_ABORT);
  181. #else
  182.   /* Signal the same code; this time it will really be fatal.  */
  183.   kill (getpid (), fatal_error_code);
  184. #endif /* not VMS */
  185. }
  186.  
  187. /* Code for dealing with Lisp access to the Unix command line */
  188.  
  189. static
  190. init_cmdargs (argc, argv, skip_args)
  191.      int argc;
  192.      char **argv;
  193.      int skip_args;
  194. {
  195.   register int i;
  196.  
  197.   Vcommand_line_args = Qnil;
  198.  
  199.   for (i = argc - 1; i >= 0; i--)
  200.     {
  201.       if (i == 0 || i > skip_args)
  202.     Vcommand_line_args
  203.       = Fcons (build_string (argv[i]), Vcommand_line_args);
  204.     }
  205. }
  206.  
  207. #ifdef VMS
  208. #ifdef LINK_CRTL_SHARE
  209. #ifdef SHAREABLE_LIB_BUG
  210. #ifdef __GNUC__
  211. #define    environ $$PsectAttributes_NOSHR$$environ
  212. extern char **environ;
  213. #else
  214. extern noshare char **environ;
  215. #endif
  216. #endif /* SHAREABLE_LIB_BUG */
  217. #endif /* LINK_CRTL_SHARE */
  218. #endif /* VMS */
  219.  
  220. /* We don't include crtbegin.o and crtend.o in the link,
  221.    so these functions and variables might be missed.
  222.    Provide dummy definitions to avoid error.
  223.    (We don't have any real constructors or destructors.)  */
  224. #ifdef __GNUC__
  225. #ifndef ORDINARY_LINK
  226. __do_clobal_ctors ()
  227. {}
  228. __do_clobal_ctors_aux ()
  229. {}
  230. __do_global_dtors ()
  231. {}
  232. char * __CTOR_LIST__[2] = { (char *) (-1), 0 };
  233. char * __DTOR_LIST__[2] = { (char *) (-1), 0 };
  234. __main ()
  235. {}
  236. #endif /* not ORDINARY_LINK */
  237. #endif /* __GNUC__ */
  238.  
  239. /* ARGSUSED */
  240. main (argc, argv, envp)
  241.      int argc;
  242.      char **argv;
  243.      char **envp;
  244. {
  245.   int skip_args = 0;
  246.   extern int errno;
  247.   extern void malloc_warning ();
  248.  
  249. /* Map in shared memory, if we are using that.  */
  250. #ifdef HAVE_SHM
  251.   if (argc > 1 && !strcmp (argv[1], "-nl"))
  252.     {
  253.       map_in_data (0);
  254.       /* The shared memory was just restored, which clobbered this.  */
  255.       skip_args = 1;
  256.     }
  257.   else
  258.     {
  259.       map_in_data (1);
  260.       /* The shared memory was just restored, which clobbered this.  */
  261.       skip_args = 0;
  262.     }
  263. #endif
  264.  
  265. #ifdef VMS
  266.   /* If -map specified, map the data file in */
  267.   if (argc > 2 && ! strcmp (argv[1], "-map"))
  268.     {
  269.       skip_args = 2;
  270.       mapin_data (argv[2]);
  271.     }
  272.  
  273. #ifdef LINK_CRTL_SHARE
  274. #ifdef SHAREABLE_LIB_BUG
  275.   /* Bletcherous shared libraries! */
  276.   if (!stdin)
  277.     stdin = fdopen (0, "r");
  278.   if (!stdout)
  279.     stdout = fdopen (1, "w");
  280.   if (!stderr)
  281.     stderr = fdopen (2, "w");
  282.   if (!environ)
  283.     environ = envp;
  284. #endif /* SHAREABLE_LIB_BUG */
  285. #endif /* LINK_CRTL_SHARE */
  286. #endif /* VMS */
  287.  
  288. #ifdef USG_SHARED_LIBRARIES
  289.   if (bss_end)
  290.     brk (bss_end);
  291. #endif
  292.  
  293. #ifdef NeXT
  294.   extern int malloc_cookie;
  295.  
  296.   /* This helps out unexnext.c.  */
  297.   if (initialized)
  298.     if (malloc_jumpstart (malloc_cookie) != 0)
  299.       printf ("malloc jumpstart failed!\n");
  300. #endif /* NeXT */
  301.  
  302.   clearerr (stdin);
  303.  
  304. #ifdef APOLLO
  305. #ifndef APOLLO_SR10
  306.   /* If USE_DOMAIN_ACLS environment variable exists,
  307.      use ACLs rather than UNIX modes. */
  308.   if (egetenv ("USE_DOMAIN_ACLS"))
  309.     default_acl (USE_DEFACL);
  310. #endif
  311. #endif /* APOLLO */
  312.  
  313. #ifndef SYSTEM_MALLOC
  314.   /* Arrange for warnings when nearly out of space.  */
  315.   malloc_init (0, malloc_warning);
  316. #endif
  317.  
  318. #ifdef HIGHPRI
  319.   setpriority (PRIO_PROCESS, getpid (), HIGHPRI);
  320.   setuid (getuid ());
  321. #endif HIGHPRI
  322.  
  323.   inhibit_window_system = 0;
  324.  
  325. #ifdef HAVE_X_WINDOWS
  326.   xargv = argv;
  327.   xargc = argc;
  328. #endif
  329.  
  330. #ifndef AMIGA
  331. /* Handle the -t switch, which specifies filename to use as terminal */
  332.   if (skip_args + 2 < argc && !strcmp (argv[skip_args + 1], "-t"))
  333.     {
  334.       skip_args += 2;
  335.       close (0);
  336.       close (1);
  337.       open (argv[skip_args], O_RDWR, 2 );
  338.       dup (0);
  339.       fprintf (stderr, "Using %s\n", argv[skip_args]);
  340. #ifdef HAVE_X_WINDOWS
  341.       inhibit_window_system = 1;    /* -t => -nw */
  342. #endif
  343.     }
  344. #endif
  345. #ifdef HAVE_X_WINDOWS
  346. /* Handle the -d switch, which means use a different display for X */
  347.   if (skip_args + 2 < argc && (!strcmp (argv[skip_args + 1], "-d") ||
  348.                    !strcmp (argv[skip_args + 1], "-display")))
  349.     {
  350.       skip_args += 2;
  351.       alternate_display = argv[skip_args];
  352.     } 
  353.   else
  354.     alternate_display = 0;
  355. #endif    /* HAVE_X_WINDOWS */
  356.  
  357.   if (skip_args + 1 < argc
  358.       && (!strcmp (argv[skip_args + 1], "-nw")))
  359.     {
  360.       skip_args += 1;
  361.       inhibit_window_system = 1;
  362.     }
  363.  
  364. /* Handle the -batch switch, which means don't do interactive display.  */
  365.   noninteractive = 0;
  366.   if (skip_args + 1 < argc && !strcmp (argv[skip_args + 1], "-batch"))
  367.     {
  368.       skip_args += 1;
  369.       noninteractive = 1;
  370.     }
  371.  
  372. #ifdef POSIX_SIGNALS
  373.   init_signals ();
  374. #endif
  375.  
  376. #ifdef HAVE_TZSET
  377.   /* Reinitialize the time zone if it was initialized before dumping Emacs.  */
  378.   if (initialized)
  379.     tzset ();
  380. #endif
  381.  
  382.   if (
  383. #ifndef CANNOT_DUMP
  384.       ! noninteractive || initialized
  385. #else
  386.       1
  387. #endif
  388.       )
  389.     {
  390.       /* Don't catch these signals in batch mode if not initialized.
  391.      On some machines, this sets static data that would make
  392.      signal fail to work right when the dumped Emacs is run.  */
  393.       signal (SIGHUP, fatal_error_signal);
  394.       signal (SIGQUIT, fatal_error_signal);
  395.       signal (SIGILL, fatal_error_signal);
  396.       signal (SIGTRAP, fatal_error_signal);
  397.       signal (SIGIOT, fatal_error_signal);
  398. #ifdef SIGEMT
  399.       signal (SIGEMT, fatal_error_signal);
  400. #endif
  401.       signal (SIGFPE, fatal_error_signal);
  402.       signal (SIGBUS, fatal_error_signal);
  403.       signal (SIGSEGV, fatal_error_signal);
  404.       signal (SIGSYS, fatal_error_signal);
  405.       signal (SIGTERM, fatal_error_signal);
  406. #ifdef SIGXCPU
  407.       signal (SIGXCPU, fatal_error_signal);
  408. #endif
  409. #ifdef SIGXFSZ
  410.       signal (SIGXFSZ, fatal_error_signal);
  411. #endif SIGXFSZ
  412.  
  413. #ifdef AIX
  414.       /* This used to run fatal_error_signal,
  415.      but it isn't fatal.  There's nothing Emacs can usefully do.
  416.      Might as well let the system kill us if it insists.  */
  417.       signal (SIGDANGER, SIG_IGN);
  418.       signal (20, fatal_error_signal);
  419.       signal (21, fatal_error_signal);
  420.       signal (22, fatal_error_signal);
  421.       signal (23, fatal_error_signal);
  422.       signal (24, fatal_error_signal);
  423. #ifdef SIGIO
  424.       signal (SIGAIO, fatal_error_signal);
  425.       signal (SIGPTY, fatal_error_signal);
  426. #endif
  427. #ifdef SIGURG
  428.       /* Note that SIGIOINT is the same as SIGIO on some machines,
  429.      and the same as SIGURG on others.  It seems ore reliable to use the
  430.      name with a uniform meaning.  */
  431.       signal (SIGURG, fatal_error_signal);
  432. #endif
  433.       signal (SIGGRANT, fatal_error_signal);
  434.       signal (SIGRETRACT, fatal_error_signal);
  435.       signal (SIGSOUND, fatal_error_signal);
  436.       signal (SIGMSG, fatal_error_signal);
  437. #endif /* AIX */
  438.     }
  439.  
  440.   noninteractive1 = noninteractive;
  441.  
  442. /* Perform basic initializations (not merely interning symbols) */
  443.  
  444.   if (!initialized)
  445.     {
  446.       init_alloc_once ();
  447.       init_obarray ();
  448.       init_eval_once ();
  449.       init_syntax_once ();    /* Create standard syntax table.  */
  450.               /* Must be done before init_buffer */
  451.       init_buffer_once ();    /* Create buffer table and some buffers */
  452.       init_minibuf_once ();    /* Create list of minibuffers */
  453.                   /* Must precede init_window_once */
  454.       init_window_once ();    /* Init the window system */
  455.     }
  456.  
  457.   init_alloc ();
  458. #ifdef MAINTAIN_ENVIRONMENT
  459.   init_environ ();
  460. #endif
  461.   init_eval ();
  462.   init_data ();
  463.   init_read ();
  464.  
  465.   init_cmdargs (argc, argv, skip_args);    /* Create list Vcommand_line_args */
  466.   init_buffer ();    /* Init default directory of main buffer */
  467.   if (!noninteractive)
  468.     {
  469. #ifdef VMS
  470.       init_vms_input ();/* init_display calls get_screen_size, that needs this */
  471. #endif /* VMS */
  472.       init_display ();    /* Determine terminal type.  init_sys_modes uses results */
  473.     }
  474.   init_keyboard ();    /* This too must precede init_sys_modes */
  475.   init_callproc ();    /* And this too. */
  476.   init_sys_modes ();    /* Init system terminal modes (RAW or CBREAK, etc.) */
  477.   init_xdisp ();
  478.   init_macros ();
  479.   init_editfns ();
  480. #ifdef VMS
  481.   init_vmsfns ();
  482. #endif /* VMS */
  483. #ifdef subprocesses
  484.   init_process ();
  485. #endif /* subprocesses */
  486.  
  487. /* Intern the names of all standard functions and variables; define standard keys */
  488.  
  489.   if (!initialized)
  490.     {
  491.       /* The basic levels of Lisp must come first */
  492.       /* And data must come first of all
  493.      for the sake of symbols like error-message */
  494.       syms_of_data ();
  495.       syms_of_alloc ();
  496. #ifdef MAINTAIN_ENVIRONMENT
  497.       syms_of_environ ();
  498. #endif MAINTAIN_ENVIRONMENT
  499.       syms_of_read ();
  500.       syms_of_print ();
  501.       syms_of_eval ();
  502.       syms_of_fns ();
  503.  
  504.       syms_of_abbrev ();
  505.       syms_of_buffer ();
  506.       syms_of_bytecode ();
  507.       syms_of_callint ();
  508.       syms_of_casefiddle ();
  509.       syms_of_callproc ();
  510.       syms_of_cmds ();
  511. #ifndef NO_DIR_LIBRARY
  512.       syms_of_dired ();
  513. #endif /* not NO_DIR_LIBRARY */
  514.       syms_of_display ();
  515.       syms_of_doc ();
  516.       syms_of_editfns ();
  517.       syms_of_emacs ();
  518.       syms_of_fileio ();
  519. #ifdef CLASH_DETECTION
  520.       syms_of_filelock ();
  521. #endif /* CLASH_DETECTION */
  522.       syms_of_indent ();
  523.       syms_of_keyboard ();
  524.       syms_of_keymap ();
  525.       syms_of_macros ();
  526.       syms_of_marker ();
  527.       syms_of_minibuf ();
  528.       syms_of_mocklisp ();
  529. #ifdef subprocesses
  530.       syms_of_process ();
  531. #endif /* subprocesses */
  532.       syms_of_search ();
  533.       syms_of_syntax ();
  534.       syms_of_undo ();
  535.       syms_of_window ();
  536.       syms_of_xdisp ();
  537. #ifdef HAVE_X_WINDOWS
  538.       syms_of_xfns ();
  539. #ifdef HAVE_X_MENU
  540.       syms_of_xmenu ();
  541. #endif /* HAVE_X_MENU */
  542. #endif /* HAVE_X_WINDOWS */
  543.  
  544. #ifdef SYMS_SYSTEM
  545.       SYMS_SYSTEM;
  546. #endif
  547.  
  548. #ifdef SYMS_MACHINE
  549.       SYMS_MACHINE;
  550. #endif
  551.  
  552.       keys_of_casefiddle ();
  553.       keys_of_cmds ();
  554.       keys_of_buffer ();
  555.       keys_of_keyboard ();
  556.       keys_of_keymap ();
  557.       keys_of_macros ();
  558.       keys_of_minibuf ();
  559.       keys_of_window ();
  560.     }
  561.  
  562.   if (!initialized)
  563.     {
  564.       /* Handle -l loadup-and-dump, args passed by Makefile. */
  565.       if (argc > 2 + skip_args && !strcmp (argv[1 + skip_args], "-l"))
  566.     Vtop_level = Fcons (intern ("load"),
  567.                 Fcons (build_string (argv[2 + skip_args]), Qnil));
  568. #ifdef CANNOT_DUMP
  569.       /* Unless next switch is -nl, load "loadup.el" first thing.  */
  570.       if (!(argc > 1 + skip_args && !strcmp (argv[1 + skip_args], "-nl")))
  571.     Vtop_level = Fcons (intern ("load"),
  572.                 Fcons (build_string ("loadup.el"), Qnil));
  573. #endif /* CANNOT_DUMP */
  574.     }
  575.  
  576.   initialized = 1;
  577.  
  578.   /* Enter editor command loop.  This never returns.  */
  579.   Frecursive_edit ();
  580.   /* NOTREACHED */
  581. }
  582.  
  583. DEFUN ("kill-emacs", Fkill_emacs, Skill_emacs, 0, 1, "P",
  584.   "Exit the Emacs job and kill it.  ARG means no query.\n\
  585. If emacs is running noninteractively and ARG is an integer,\n\
  586. return ARG as the exit program code.")
  587.   (arg)
  588.      Lisp_Object arg;
  589. {
  590.   Lisp_Object answer;
  591.   int i;
  592.   struct gcpro gcpro1;
  593.  
  594.   GCPRO1 (arg);
  595.  
  596.   if (!EQ (Vkill_emacs_hook, Qnil))
  597.     call0 (Vkill_emacs_hook);
  598.  
  599.   if (feof (stdin))
  600.     arg = Qt;
  601.  
  602. #ifdef subprocesses
  603.   kill_buffer_processes (Qnil);
  604. #endif /* subprocesses */
  605.  
  606. #ifdef VMS
  607.   kill_vms_processes ();
  608. #endif /* VMS */
  609.  
  610.   Fdo_auto_save (Qt);
  611.  
  612. #ifdef CLASH_DETECTION
  613.   unlock_all_files ();
  614. #endif /* CLASH_DETECTION */
  615.  
  616.   fflush (stdout);
  617.   reset_sys_modes ();
  618.   UNGCPRO;
  619.  
  620. /* Is it really necessary to do this deassign
  621.    when we are going to exit anyway?  */
  622. /* #ifdef VMS
  623.   stop_vms_input ();
  624.  #endif  */
  625.   stuff_buffered_input (arg);
  626. #ifdef SIGIO
  627.   /* There is a tendency for a SIGIO signal to arrive within exit,
  628.      and cause a SIGHUP because the input descriptor is already closed.  */
  629.   unrequest_sigio ();
  630.   signal (SIGIO, SIG_IGN);
  631. #endif
  632.   exit ((XTYPE (arg) == Lisp_Int) ? XINT (arg)
  633. #ifdef VMS
  634.     : 1
  635. #else
  636.     : 0
  637. #endif
  638.     );
  639.   /* NOTREACHED */
  640. }
  641.  
  642. #ifndef CANNOT_DUMP
  643. /* Nothing like this can be implemented on an Apollo.
  644.    What a loss!  */
  645.  
  646. #ifdef HAVE_SHM
  647.  
  648. DEFUN ("dump-emacs-data", Fdump_emacs_data, Sdump_emacs_data, 1, 1, 0,
  649.   "Dump current state of Emacs into data file FILENAME.\n\
  650. This function exists on systems that use HAVE_SHM.")
  651.   (intoname)
  652.      Lisp_Object intoname;
  653. {
  654.   extern int my_edata;
  655.   Lisp_Object tem;
  656.   extern void malloc_warning ();
  657.  
  658.   CHECK_STRING (intoname, 0);
  659.   intoname = Fexpand_file_name (intoname, Qnil);
  660.  
  661.   tem = Vpurify_flag;
  662.   Vpurify_flag = Qnil;
  663.  
  664.   fflush (stdout);
  665.   /* Tell malloc where start of impure now is */
  666.   /* Also arrange for warnings when nearly out of space.  */
  667. #ifndef SYSTEM_MALLOC
  668.   malloc_init (&my_edata, malloc_warning);
  669. #endif
  670.   map_out_data (XSTRING (intoname)->data);
  671.  
  672.   Vpurify_flag = tem;
  673.  
  674.   return Qnil;
  675. }
  676.  
  677. #else /* not HAVE_SHM */
  678.  
  679. DEFUN ("dump-emacs", Fdump_emacs, Sdump_emacs, 2, 2, 0,
  680.   "Dump current state of Emacs into executable file FILENAME.\n\
  681. Take symbols from SYMFILE (presumably the file you executed to run Emacs).")
  682.   (intoname, symname)
  683.      Lisp_Object intoname, symname;
  684. {
  685.   extern int my_edata;
  686.   Lisp_Object tem;
  687.   extern void malloc_warning ();
  688.  
  689.   CHECK_STRING (intoname, 0);
  690.   intoname = Fexpand_file_name (intoname, Qnil);
  691.   if (!EQ (symname, Qnil))
  692.     {
  693.       CHECK_STRING (symname, 0);
  694.       if (XSTRING (symname)->size)
  695.     symname = Fexpand_file_name (symname, Qnil);
  696.     }
  697.  
  698.   tem = Vpurify_flag;
  699.   Vpurify_flag = Qnil;
  700.  
  701.   fflush (stdout);
  702. #ifdef VMS
  703.   mapout_data (XSTRING (intoname)->data);
  704. #else
  705.   /* Tell malloc where start of impure now is */
  706.   /* Also arrange for warnings when nearly out of space.  */
  707. #ifndef SYSTEM_MALLOC
  708.   malloc_init (&my_edata, malloc_warning);
  709. #endif
  710.   unexec (XSTRING (intoname)->data,
  711.       !EQ (symname, Qnil) ? XSTRING (symname)->data : 0, &my_edata, 0, 0);
  712. #endif /* not VMS */
  713.  
  714.   Vpurify_flag = tem;
  715.  
  716.   return Qnil;
  717. }
  718.  
  719. #endif /* not HAVE_SHM */
  720.  
  721. #endif /* not CANNOT_DUMP */
  722.  
  723. #ifdef VMS
  724. #define SEPCHAR ','
  725. #else
  726. #ifdef AMIGA            /* Can't use : on Amiga */
  727. #define SEPCHAR ','
  728. #else
  729. #define SEPCHAR ':'
  730. #endif
  731. #endif
  732.  
  733. Lisp_Object
  734. decode_env_path (evarname, defalt)
  735.      char *evarname, *defalt;
  736. {
  737.   register char *path, *p;
  738.   extern char *index ();
  739.  
  740.   Lisp_Object lpath;
  741.  
  742.   if (evarname != 0)
  743.     path = (char *) egetenv (evarname);
  744.   else
  745.     path = 0;
  746.   if (!path)
  747.     path = defalt;
  748.   lpath = Qnil;
  749.   while (1)
  750.     {
  751.       p = index (path, SEPCHAR);
  752.       if (!p) p = path + strlen (path);
  753.       lpath = Fcons (p - path ? make_string (path, p - path) : Qnil,
  754.              lpath);
  755.       if (*p)
  756.     path = p + 1;
  757.       else
  758.     break;
  759.     }
  760.   return Fnreverse (lpath);
  761. }
  762.  
  763. syms_of_emacs ()
  764. {
  765. #ifndef CANNOT_DUMP
  766. #ifdef HAVE_SHM
  767.   defsubr (&Sdump_emacs_data);
  768. #else
  769.   defsubr (&Sdump_emacs);
  770. #endif
  771. #endif /* not CANNOT_DUMP */
  772.  
  773.   defsubr (&Skill_emacs);
  774.  
  775.   DEFVAR_LISP ("command-line-args", &Vcommand_line_args,
  776.     "Args passed by shell to Emacs, as a list of strings.");
  777.  
  778.   DEFVAR_LISP ("system-type", &Vsystem_type,
  779.     "Symbol indicating type of operating system you are using.");
  780.   Vsystem_type = intern (SYSTEM_TYPE);
  781.  
  782.   DEFVAR_BOOL ("noninteractive", &noninteractive1,
  783.     "Non-nil means Emacs is running without interactive terminal.");
  784.  
  785.   Vkill_emacs_hook = Qnil;
  786.  
  787.   DEFVAR_LISP ("kill-emacs-hook", &Vkill_emacs_hook,
  788.     "Function called, if non-nil, whenever kill-emacs is called.");
  789. }
  790.